#	CancelWindowCheckOut - revert to an old copy of a checked-out window
#
#	Usage:	CancelWindowCheckOut window
#
#	Status:	CancelWindowCheckOut may return the following status values:
#
#			0		the window was reverted
#			1		error
#			4		the user canceled
#
#	CancelWindowCheckOut cancels the changes that have been made
#	to a file in a window.
#
#	© 1988, 1989 Apple Computer, Inc.
#	All rights reserved.

Set Exit 0
Set CaseSensitive 0

# the following helps to debug until MPW sends echos to Dev:Console instead of Dev:StdErr
If {Echo} == 1
	Set somewhere "·· '{Worksheet}¶'"
Else
	Set somewhere '· Dev:Null'
End

Begin

	Set Window "{1}"

	# get short name of window

	If "{Window}" !~ /:*([Â:]+:*)*([Â:]+)¨1/
		Exit 1
	End
	Set Short "{¨1}"					# get short name for dialogs
	Set Cant "Changes to Ò{Short}Ó canÕt be discarded"

	# check what project the window belongs to

	Set Info "`ProjectInfo "{Window}"`"
###	If "{Info}" !~ /ÅProject: (Åº)¨1 Å/
	If "{Info}" !~ /ÅProject: (Å)¨1     Checked out: Å/
		Alert "{Cant} because it doesnÕt belong to a project."
		Exit 1
	End
	Set Project "{¨1}"

	# ensure that the window is checked out

	If "{Info}" !~ /[Â,]+,[Â ¶t]+¶+Å/
		Alert "{Cant} because it wasnÕt checked out."
		Exit 1
	End

	# check if the project is mounted

	Set Info "`ProjectInfo -only -project "{Project}"; Set InfoStatus {Status}`"
	If {InfoStatus} != 0
		Alert "{Cant} because the project Ò{Project}Ó is not mounted."
		Exit 1
	End

	# *** what about a way to start over (get a new modifiable)?
	# *** in that case, what about introducing a new branch?
	CheckOut -project "{Project}" -cancel "{Window}"
	Set CheckOutStatus {Status}
	Exit {CheckOutStatus}

End {somewhere}
